<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
	class Admin_log_model extends CI_Model{
		
		function __construct()
		{
			parent::__construct();
			$this->table = 'admin_log';
			$this->admin_table = 'admin';
		}
		
		function Get($uid = '')
		{
			return $this->db->select('*')
			  ->from($this->table)
			  ->where('id' , $uid)
			  ->get()
			  ->row_array();
		}
		function info()
		{
			return $this->db->select('*')
			  ->from($this->table)
			  ->where('user_id' , $this->userinfo['user_id'])
			  ->get()
			  ->row_array();
		}
		
		public function getCount($where){
			$this->db->select('count(*) as mun,sum(total) as total,sum(balance) as balance,sum(frost) as frost,sum(await) as await,sum(repay) as repay');
			$this->db->from($this->table);
			$this->db->join($this->user_table, $this->table.'.user_id = '.$this->user_table.'.user_id', 'left');
			$this->db->join($this->userinfo_table, $this->table.'.user_id = '.$this->userinfo_table.'.user_id', 'left');
			$this->db->where($where);
			$query = $this->db->get();
			//return $query->num_rows();
			return $query->row_array();
		}
		public function getUsersetCount($where,$like=''){
			$this->db->select($this->table.'.*,'.$this->user_table.'.username,'.$this->user_table.'.truename');
			$this->db->from($this->table);
			$this->db->join($this->user_table, $this->table.'.user_id = '.$this->user_table.'.id', 'left');
			$this->db->where($where);
			if($like != ''){
				$this->db->like($this->table.'.content',$like);
			}
			$query = $this->db->get();
			return $query->num_rows();
			//return $query->row_array();
		}
		public function getList($where,$page,$limit,$like ='')
	    {
			$this->db->select($this->table.'.*,'.$this->user_table.'.username,'.$this->user_table.'.truename');
			$this->db->from($this->table);
			$this->db->join($this->user_table, $this->table.'.user_id = '.$this->user_table.'.id', 'left');
			$this->db->where($where);			
			if($like != ''){
				$this->db->like($this->table.'.content',$like);
			}
			$this->db->order_by("id", "desc");
			$this->db->limit($limit, $page);
			$query = $this->db->get();
			return $query->result_array();
	    }
		

		function insert($data)
		{
			
			$logdata = array();
			$logdata['user_id'] = $data['user_id'];
            $logdata['username'] = $data['username'];
			$logdata['event'] = $data['event'];
			$logdata['content'] = $data['content'];
			$logdata['ip'] = $this->input->ip_address();
			$logdata['add_time'] = time();
			$this->db->insert($this->table, $logdata);
			return $this->db->affected_rows();
		}
		
		function update($data,$user_id)
		{
			return $this->db->where('user_id',$user_id)->update($this->table, $data);
		}
		
		
		
		
	}